package com.atguigu.gmall.product.controller;


import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.product.model.BaseTrademark;
import com.atguigu.gmall.product.model.CategoryTrademarkVo;
import com.atguigu.gmall.product.service.BaseCategoryTrademarkService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

// 分类品牌中间表 前端控制器

@Api(tags = "分类品牌中间表控制器")
@RestController
@RequestMapping("/admin/product")
public class BaseCategoryTrademarkController {

    @Autowired
    private BaseCategoryTrademarkService baseCategoryTrademarkService;


    //查询当前分类关联的品牌列表

    @GetMapping("/baseCategoryTrademark/findTrademarkList/{category3Id}")
    public Result getTrademarkByCategoryId(@PathVariable("category3Id") Long category3Id) {
        List<BaseTrademark> trademarkList = baseCategoryTrademarkService.getTrademarkByCategoryId(category3Id);
        return Result.ok(trademarkList);
    }


    //查询未关联到当前分类品牌列表

    @GetMapping("/baseCategoryTrademark/findCurrentTrademarkList/{category3Id}")
    public Result getCurrentTrademarkList(@PathVariable("category3Id") Long category3Id) {
        List<BaseTrademark> trademarkList = baseCategoryTrademarkService.getCurrentTrademarkList(category3Id);
        return Result.ok(trademarkList);
    }


    //将选中品牌关联当前分类

    @PostMapping("/baseCategoryTrademark/save")
    public Result saveBaseCategoryTrademark(@RequestBody CategoryTrademarkVo categoryTrademarkVo) {
        baseCategoryTrademarkService.saveBaseCategoryTrademark(categoryTrademarkVo);
        return Result.ok();
    }


    //删除指定分类下关联品牌

    @DeleteMapping("/baseCategoryTrademark/remove/{category3Id}/{trademarkId}")
    public Result deleteCategoryTrademark(@PathVariable("category3Id") Long category3Id,
                                          @PathVariable("trademarkId") Long trademarkId) {
        baseCategoryTrademarkService.deleteCategoryTrademark(category3Id, trademarkId);
        return Result.ok();
    }
}
